﻿using Castle.ActiveRecord;
using EntityLayer.Entities;

namespace UnitTests
{
    /// <summary>
    /// singleton activerecord configuration management
    /// </summary>
    public class TestFoundation
    {
        //encapsulated singleton object
        private static TestFoundation innerInstance = null;
        //private static singleton constructor
        static TestFoundation()
        {
            ActiveRecordStarter.Initialize();
            ActiveRecordStarter.RegisterAssemblies(typeof (User).Assembly);
        }
        /// <summary>
        /// public singleton instance accessor
        /// </summary>
        public static TestFoundation Instance
        {
            get
            {
                if (innerInstance == null)
                    innerInstance = new TestFoundation();
                return innerInstance;
            }
        }
        /// <summary>
        /// ensures a clean database
        /// </summary>
        public void CreateEmptyDatabase()
        {
            TearDownDatabase();
            ActiveRecordStarter.CreateSchema();
        }
        /// <summary>
        /// destroys a database
        /// </summary>
        public void TearDownDatabase()
        {
            ActiveRecordStarter.DropSchema();
        }
    }
}